package examples;

import com.sun.org.omg.CORBA.ParameterModeHelper;

import jade.core.Profile;
import jade.core.ProfileException;
import jade.core.ProfileImpl;
import jade.core.Runtime;

import jade.tools.rma.rma;
import jade.util.leap.Properties;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;

public class StartAgentPlatform {

	/**
	 * @param args
	 * @throws ProfileException 
	 */
	
	@SuppressWarnings("unused")
	public static void main(String[] args) throws ProfileException {
		String host = "localhost";
		String port = "";
		String name = "AOP";
		
		ContainerController cController;
		Runtime rt = Runtime.instance();//retrieve the singleton instance of the JADE Runtime
		Profile p;
		//Create a container
		p = new ProfileImpl();
		cController = rt.createMainContainer(p);			
		rt.setCloseVM(true);
		
		
		
		if(cController != null){
			try{
				//start GUI interface Agent
				AgentController ac = cController.createNewAgent("gui", rma.class.getName(), null);
				ac.start();
				
				//---add Agents in this zone---
				
				//add Agent - register agent into DF, receive acl msg, printout and reply
				if(args[0].equalsIgnoreCase("party"))
				{
					CreateAgent(cController, "host","examples.party.HostAgent");
				}
				else if(args[0].equalsIgnoreCase("ping"))
				{
					CreateAgent(cController, "ping1","examples.PingAgent.PingAgent");
				}
				else if(args[0].equalsIgnoreCase("complex behaviour"))
				{
					CreateAgent(cController, "complex","examples.behaviours.ComplexBehaviourAgent");
				}
				else if(args[0].equalsIgnoreCase("state machine behaviour"))
				{
					CreateAgent(cController, "fsm","examples.behaviours.FSMAgent");
				}
				else if(args[0].equalsIgnoreCase("simple behaviour"))
				{
					CreateAgent(cController, "simple","examples.behaviours.SimpleAgent");
				}
				else if(args[0].equalsIgnoreCase("timer behaviour"))
				{
					CreateAgent(cController, "time","examples.behaviours.TimeAgent");
				}
				

				else if(args[0].equalsIgnoreCase("yellow pages"))
				{
					CreateAgent(cController, "regAgent","examples.yellowPages.DFRegisterAgent");
					CreateAgent(cController, "searchAgent","examples.yellowPages.DFSearchAgent");
					CreateAgent(cController, "subscriber","examples.yellowPages.DFSubscribeAgent");
				}
				
				
			}
			catch (Exception e){
				e.printStackTrace();
			}
		}	
	}
	
	private static void CreateAgent(ContainerController cController, String agent_name, String agent_class) throws StaleProxyException{
		//add Agent AgentSender
		AgentController ac = cController.createNewAgent(agent_name, agent_class, null);
		ac.start();
	}
}
